<?php

use yii\helpers\Html;
use yii\grid\GridView;
use kartik\date\DatePicker;
use yii\helpers\Url;

$this->title = Yii::t('app', 'Costs');
$this->params['breadcrumbs'][] = $this->title;
?>
<style type="text/css">
    .cs1{margin:2px 5px;} 
</style>

<div class="cost-index">

    <div class="box">
        <div class="box-header">
            <h4>成本项列表</h4>   
        </div>
        <div class="box-body">

       <!--  <p>
             </?php echo $this->render('_search_list', ['model' => $searchModel]); ?>
        </p> -->

        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'layout'  =>  "{items}\n{summary}\n{pager}",
            'options' => [
                'style'=>'overflow: auto; word-wrap: break-word;'
            ],
            'columns' => [
                ['class' => 'yii\grid\SerialColumn'],
                
                [
                    'attribute' => 'product.code',
                    'headerOptions' => ['width' => '10%'],
                    'value' => function ($model) {
                            return $model->product->code;
                    },
                ],

                [
                    'attribute' => 'product.name',
                    'headerOptions' => ['width' => '10%'],
                    'value' => function ($model) {
                            return $model->product->name;
                    },
                ],
               
                [
                    'attribute' => 'cost_type',
                    'headerOptions' => ['width' => '10%'],
                    'value' => function ($model) {
                            return \yii::$app->params['cost_type'][$model->cost_type];
                        },
                ],
        
                [
                    'attribute' => 'supplier.en_name',
                    'headerOptions' => ['width' => '10%'],
                    'value' => function ($model) {
                            return $model->supplier->en_name;
                    },
                ],

                [
                    'attribute' => 'payment',
                    'headerOptions' => ['width' => '5%'],
                    'value' => function ($model) {
                            return \yii::$app->params['payment_type'][$model->payment];
                        },
                ],
                [
                    'attribute' => 'day_num',
                    'headerOptions' => ['width' => '5%'],
                    'value' => function ($model) {
                            return $model->dayNum;
                        },
                ],

                [
                    'attribute' => 'price',
                    'headerOptions' => ['width' => '5%'],
                    'value' => function ($model) {
                            return $model->price;
                        },
                ],

                [
                    'attribute' => 'remark',
                    'headerOptions' => ['width' => '15%'],
                    'value' => function ($model) {
                            return $model->remark;
                        },
                ],
                [
                    'attribute' => 'status',
                    'filter' =>  Yii::$app->params['status'],
                    'headerOptions' => ['width' => '5%'],
                    'value' => function ($model) {
                            return \yii::$app->params['status'][$model->status];
                        },
                ],

                

                [
                    'attribute' => 'user_id',
                    'headerOptions' => ['width' => '5%'],
                    'value' => function ($model) {
                            return $model->userName;
                        },
                ],

                
                
                [
                    'attribute' => 'confirm',
                    'filter' =>  Yii::$app->params['confirm'],
                    'headerOptions' => ['width' => '5%'],
                    'value' => function ($model) {
                            return \yii::$app->params['confirm'][$model->confirm];
                        },
                ],
                
                [
                    'attribute' => 'payment_time',
                    'headerOptions' => ['width' => '5%'],
                    'value' => function ($model) {
                            return $model->payment_time;
                        },
                ],

                [
                    'label' => Yii::t('app.cost', 'Attachment'),
                    'format'=>'raw',
                    'headerOptions' => ['width' => '5%'],
                    'value' => function ($model) {
                        $str = '';
                        if($model->file_path){ 
                            $str = "<a class='cs1 btn btn-info btn-xs' href='/cost/cost/download?id=$model->id' >下载附件</a>";
                        }
                        return $str;
                    },
                ],

                [
                    'label'=>'操作',
                    'format'=>'raw',
                    'headerOptions' => ['width' => '5%'],
                    'value' => function($model){
                        $str = '';
                        if($model->confirm != 2){

                            return "<a class='btn btn-success btn-xs create_excel' href='javascript:;' title='生成确认单' data-id='$model->id'>确认</a>";
                            // $str = Html::a('确认', ['confirm', 'id' => $model->id], ['class' => 'btn btn-success btn-xs cs1','data' => [
                            //             'confirm' => Yii::t('app', '你确定要吗?'),
                            //             'method' => 'post',
                            // ],]);
                        }
                        return $str;
                     }
                ],
            ],
        ]); ?>
        </div>
    </div>

</div>

<div class="modal fade config-modal"  role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog " role="document" style="width:600px;">
      <div class="modal-content" style="padding: 10px;">
        <form id="config-form" method="get" action="<?=Url::toRoute(['/cost/cost/confirm'])?>" style="margin: 20px;">
            <input type="hidden" name="id" id="order-id" value="">
           
            <div class="form-group">
                <?php 
                echo '<label>付款时间</label>';
                echo DatePicker::widget([
                    'id' => 'payment_time',
                    'name' => 'payment_time', 
                    'value' => '',
                    'options' => ['placeholder' => '选择日期'],
                    'pluginOptions' => [
                        'format' => 'yyyy-mm-dd',
                        'autoclose'=>true,
                        'todayHighlight' => true
                    ]
                ]);
                ?>
            </div>

        </form>
        <div class="text-center" style="padding: 10px;">
            <button class="btn btn-success" id="create">确认付款</button>
        </div>  
      </div>
  </div>
</div>


<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">


$(".config-modal").on("hidden.bs.modal", function() {
    $(this).removeData("bs.modal");
});

$(".create_excel").click(function(){
     $('.config-modal').modal('show');
     var order_id = $(this).attr("data-id");
     $("#order-id").val(order_id);
});

$("#create").click(function(){
    var payment_time = $("#payment_time").val();
    if(!payment_time){
        alert("时间不能为空！");
        return false;
    }
    $("#config-form").submit();
});
</script>
<?php app\components\JsBlock::end() ?> 